<?
header('content-type:text/html;charset=utf-8');
class Pass_Controller extends Base_Controller {

   
    public function action_login()
    {
        return View::make('pass.login');
    }


     public function action_logout()
    {   
        Session::forget('username');
        return View::make('jump.error2',array('msg'=>'退出成功','time'=>3,'url'=>'login'));
    }


    public function action_dologin()
    {
        $username = Input::get('username');
        $password = Input::get('password');
        $user = DB::query("select * from user where username='$username' and password='$password'");
        if($user){
            Session::put('username',$username);
            return Redirect::to('home/index');
        }else{
            $warnings[] = '该用户或密码错误';
            return View::make('pass/login', array('warnings' => $warnings));
        }

    }

    public function action_register()
    {
        return View::make('pass/register');
    }

    public function action_doregister()
    {
        $username = Input::get('username');
        $phone = Input::get('phone');
        $email = Input::get('email');
        $password = Input::get('password');
        $sex = Input::get('sex');
        $time = time();      
        $re=DB::table('user')->where('username','=',$username)->get();
        if($re){
            return View::make('jump.error2',array('msg'=>'用户名已存在','time'=>3,'url'=>'register'));
        }else{
            $res=DB::table('user')->insert(array('username'=>$username,'phone'=>$phone,'email'=>$email,'password'=>$password,'sex'=>$sex,'regtime'=>$time));
            if($res){
                return View::make('jump.error2',array('msg'=>'注册成功',"time"=>3,'url'=>'login'));
            }else{
                return View::make('jump.error2',array('msg'=>'注册失败',"time"=>3,'url'=>'register'));
            }
        }
    }








}